from PyQt5.QtWidgets import *
from PyQt5.QtCore import QThread, pyqtSignal
import sys


class ui(QWidget):
    def __init__(self):
        super().__init__()

        layout=QVBoxLayout(self)

        layout.addWidget(QPushButton('开始',self,clicked=self.down))
        self.btn=QPushButton('测试',self)
        self.bar=QProgressBar()
        layout.addWidget(self.bar)
        layout.addWidget(self.btn)

        #实例化线程
        self.mythread=thread(data=self)



    def down(self):
        print('按钮被按下')
        self.mythread.start()

class thread(QThread):
    signal = pyqtSignal(int)

    def __init__(self, data, parent=None):
        QThread.__init__(self, parent)
        self.data=data
        self.signal.connect(self.update)

    def run(self):
        for i in range(100):

            self.sleep(1)
            self.data.btn.setText(str(i))
            self.signal.emit(i)


    def update(self,value):
        self.data.bar.setValue(value)

if __name__ == '__main__':
    app=QApplication(sys.argv)
    ui=ui()
    ui.show()
    sys.exit(app.exec())